package com.kingtao.util;

import com.kingtao.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author: kingtao
 * @Date: 2023-07-24-10:43
 * @Description:
 */
public abstract class Config {
    static Properties properties;

    static {
        try {
            InputStream in = Config.class.getResourceAsStream("/application.properties");
            properties = new Properties();
            properties.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    public static int getServerPort() {
        String value = properties.getProperty("server.port");
        if (value == null) {
            return 8080;
        }else {
            return Integer.parseInt(value);
        }
    }

    public static Serializer.Algorithm getSerializerAlgorithm() {
        String value = properties.getProperty("serializer.algorithm");
        switch (value) {
            case "Java":
                return Serializer.Algorithm.Java;
            case "Json":
                return Serializer.Algorithm.Json;
            default:
                return Serializer.Algorithm.Json;
        }
    }

}
